require("../util.js");
require("../component/components.js");
require("../../jsMt/util.js");
var vm = new Vue({
    el:"#applyRefund",
    data:{
        name:"申请退款",
        num:"",  //1 申请退款
        uid:"",
        orderNumber:"",
        // express:"请选择退款原因",
        refundcontact:"",  //退款联系人
        refundReason:"请选择退款原因",  //退款原因
        refundTelephone:"",//退款电话
        state:"",  //1默认为添加2为修改
        type:"",// 退款类型 1退款2退货退款
        typeName:"请选择退款类型",
        expresLists:{}
    },
    mounted:function(){
        this.searchObject = this.getQueryStringArgs();
        this.uid=this.searchObject&&this.searchObject.uid;
        this.orderNumber=this.searchObject&&this.searchObject.orderNumber;
        this.num=this.searchObject&&this.searchObject.type;
        if(this.num==2){
            this.name="申请售后";
        }
        // this.userOrderInfo();
        // this.expresList();
    },
    methods:{
        //后退
        getBack:function(){
            history.go(-1);
        },
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        /*获取查询字符对象*/
        getQueryStringArgs: function () {
            //取得查询字符串并去掉开头的问号
            var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
                args = {},
                items = qs.length ? qs.split("&") : [],
                item = null,
                name = null,
                value = null,
                len = items.length;
            for (var i = 0; i < len; i++) {
                item = items[i].split("=");
                name = item[0];
                value = item[1];
                if (name.length) {
                    args[name] = value;
                }
            }
            return args;
        },
        getSelet:function(index){
            var that=this;
            var data=[];
            if(index==1){
                data = [
                    { "id": "0", "value": "订单不能按预计时间送达" },
                    { "id": "1", "value": "操作有误（商品、地址等选错）" },
                    { "id": "2", "value": "重复下单/误下单" },
                    { "id": "2", "value": "其他渠道价格更低" },
                    { "id": "2", "value": "该商品降价了" },
                    { "id": "2", "value": "不想买了" },
                    { "id": "2", "value": "其它原因" }
                ];
            }else if(index==2){
                data = [
                    // { "id": "1", "value": "仅退款" },
                    { "id": "2", "value": "退款退货" }
                ];
            }
            var bankSelect = new IosSelect(1,
                [data],
                {
                    container: '.provingMode',
                    itemHeight: 30,
                    itemShowCount: 3,
                    callback: function (selectOneObj) {
                        console.log(selectOneObj);
                        if(index==1){
                            that.refundReason=selectOneObj.value;
                        }else if(index==2){
                            that.typeName=selectOneObj.value;
                            that.type=selectOneObj.id;
                        }

                        //that.sellerupdatecloseorder(selectOneObj.value);
                    }
                });
        },
        //提交申请
        userOrderRefund:function(){
            var that=this;
            if(!that.refundReason){
                vm.$refs.prompt.toast("请选择退款原因！");
                return false;
            }
            if(!that.refundcontact){
                vm.$refs.prompt.toast("请填写退款联系人！");
                return false;
            }
            if(!that.refundTelephone){
                vm.$refs.prompt.toast("请填写退款电话！");
                return false;
            }
            var data={
                loginUid:that.uid,
                orderNumber:that.orderNumber,
                refundcontact:that.refundcontact,
                refundReason:that.refundReason,
                refundTelephone:that.refundTelephone,
                state:1
            },url;
            if(that.num==1){
                url="/purchase/userOrderRefund";
            }else if(that.num==2){
                if(!that.type){
                    vm.$refs.prompt.toast("请选择退款类型！");
                    return false;
                }
                data.type=that.type;
                url="/purchase/userOrderRefundAfter";
            }
            console.log(data)
            that.ajax({url:url,data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0){
                    that.getBack();
                }else{
                    vm.$refs.prompt.toast("操作失败！");
                }
            });
        },
        getNext:function(num){
            if(num==1){
                location.href="/addAddress?type=3&uid="+this.uid+"&addressId="+this.address.addressId+"&orderNumber="+this.orderNumber;
            }
        }
    }
});